package 笔试2.wangyi.four;


import java.util.*;

import static MyUtils.MHUtils.can;
import static MyUtils.MHUtils.ptCharShuzu;

public class Main {
    static char[][] g,vis;
    static List<List<int[]>> res = new ArrayList<>();
    static List<int[]> tmp = new ArrayList<>();
    static int m,n;
    static  int s=0;
    static   int resMin=99999;
    static    Map<Integer, List> map = new HashMap<>();

    static  int A;
    static  int B;
//   @Test
//   public void test() {
public static void main(String[] args) {


//        g= new char[][]{
//                {'*','#'},
//                {'#','*'}
//        };
       Scanner sc = new Scanner(System.in);
       n = sc.nextInt();
       m=n;
       int a = sc.nextInt();A=a;
       int b = sc.nextInt();B=b;

       String[] ss = new String[n];
       sc.nextLine();
       for (int i = 0; i < n; i++) {
           ss[i]=sc.nextLine();
       }

       char[][] G = new char[n][n];
       for (int i = 0; i < n; i++) {
           char[] row = ss[i].toCharArray();
           for (int j = 0; j < n; j++) {
               G[i][j]=row[j];
           }
       }
       g=G;

        if(g==null || (n==1)){
            System.out.println(0);
            return;
        }



        //开始


       for (int i = 0; i < g.length; i++) {
           for (int j = 0; j < g[0].length; j++) {
               if(g[i][j]=='*'){
                   csm.add(new int[]{i,j});
               }
           }
       }

//        Scanner sc = new Scanner(System.in);
//        m=sc.nextInt();
//        n=sc.nextInt();
//
//        g=new int[m][n];
//        for (int i = 0; i < m; i++) {
//            for (int j = 0; j < n; j++) {
//                g[i][j]=sc.nextInt();
//            }
//        }


        g[0][0]='v';
        bT(0,0);
//       System.out.println("res:"+resM);
       System.out.println(resM);

    }
    static int sum=0;
    static int resM=99999;
    static List<int[]> csm = new ArrayList<>();

    /*

4 5 10
....
.##.
.##.
....

     */
    private static void bT(int i, int j) {
//        ptCharShuzu(g);
        if(i==m-1 && j==n-1){
            resM = Math.min(sum,resM);
            return;
        }

        for (int k = 0; k < fx.length; k++) {
            int x = i+fx[k][0], y = j+fx[k][1];
            if(x<0 || x>=n || y<0 || y>=m || g[x][y]=='v' ) {
                continue;
            }
            if(x>=0&& y>=0 && x<n && y<n ) {

                char cur=g[x][y];
                if(cur=='#'){
                    sum+=A;//a
                }
                char tmp =cur;
                g[x][y]='v';

    //            System.out.println("cur"+cur);
                    bT(x, y);

                g[x][y]=tmp;
                if(tmp=='#')sum-=A;
            }

        }

        if(g[i][j]=='*'){

            for (int k = 0; k < csm.size(); k++) {
                int csmi=csm.get(k)[0],csmj=csm.get(k)[1];
                if(csmi==i && csmj==j)continue;
                if(g[csmi][csmj]=='v')continue;
                if(csmi>=0&& csmj>=0 && csmi<n && csmj<n ) {

                    g[csmi][csmj] = 'v';
                    sum += B;//b

                    bT(csmi, csmj);

                    g[csmi][csmj] = '*';
                    sum -= B;
                }
            }
        }
    }

    static int[][] fx = {
            {-1,0},
            {1,0},
            {0,-1},
            {0,1}
    };
}
